<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>EDE图形化编程系统</title>
    <link rel="stylesheet"
          href="${request.contextPath}/statics/plugins/layui2.5.4/css/modules/laydate/default/laydate.css">
    <link rel="stylesheet" href="${request.contextPath}/statics/plugins/layui2.5.4/css/layui.css">
    <!-- Tell the browser to be responsive to screen width -->
    <meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
    <link rel="stylesheet" href="${request.contextPath}/statics/css/bootstrap.min.css">
    <link rel="stylesheet" href="${request.contextPath}/statics/css/font-awesome.min.css">
    <link rel="stylesheet" href="${request.contextPath}/statics/css/AdminLTE.min.css">
    <!-- AdminLTE Skins. Choose a skin from the css/skins
         folder instead of downloading all of them to reduce the load. -->
    <link rel="stylesheet" href="${request.contextPath}/statics/css/all-skins.min.css">
    <link rel="stylesheet" href="${request.contextPath}/statics/css/main.css">
    <link rel="stylesheet" href="${request.contextPath}/statics/plugins/layui2.5.4/css/layui.css">
    <!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
    <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
    <!--[if lt IE 9]>
    <script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
    <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
    <![endif]-->
</head>
<body class="hold-transition login-page">
<div class="login-box" id="rrapp" v-cloak>
    <div class="login-logo">
        <b>EDE图形化编程系统</b>
    </div>
    <!-- /.login-logo -->
    <div class="login-box-body" v-show="showFlag">
        <!--<p class="login-box-msg">管理员登录</p>-->
        <div v-if="error" class="alert alert-danger alert-dismissible">
            <h4 style="margin-bottom: 0px;"><i class="fa fa-exclamation-triangle"></i> {{errorMsg}}</h4>
        </div>
        <div class="form-group has-feedback">
            <input type="text" class="form-control" v-model="username" placeholder="账号">
            <span class="glyphicon glyphicon-user form-control-feedback"></span>
        </div>
        <div class="form-group has-feedback">
            <input type="password" class="form-control" v-model="password" placeholder="密码">
            <span class="glyphicon glyphicon-lock form-control-feedback"></span>
        </div>
        <div class="form-group has-feedback">
            <input type="text" class="form-control" v-model="captcha" @keyup.enter="login" placeholder="验证码">
            <span class="glyphicon glyphicon-warning-sign form-control-feedback"></span>
        </div>
        <div class="form-group has-feedback">
            <img alt="如果看不清楚，请单击图片刷新！" class="pointer" :src="src" @click="refreshCode">
            &nbsp;&nbsp;&nbsp;&nbsp;<a href="javascript:;" @click="refreshCode">点击刷新</a>
        </div>
        <div class="row">
            <!--<div class="col-xs-8">
              <div class="checkbox icheck">
              </div>
            </div>-->
            <!-- /.col -->
            <div class="col-xs-2"></div>
            <div class="col-xs-4">
                <button type="button" class="btn btn-primary btn-block btn-flat" @click="login">登录</button>
            </div>
            <div class="col-xs-4">
                <button type="button" class="btn btn-primary btn-block btn-flat" @click="register">注册</button>
            </div>
            <!-- /.col -->
        </div>
        <!-- /.social-auth-links -->

    </div>
    <div class="login-box-body" v-show="!showFlag">
        <p class="login-box-msg">注册</p>
        <div class="form-group has-feedback">
            <input type="text" class="form-control" v-model="registe.username" placeholder="账号">
            <span class="glyphicon glyphicon-user form-control-feedback"></span>
        </div>
        <div class="form-group has-feedback">
            <input type="password" class="form-control" v-model="registe.password" placeholder="密码">
            <span class="glyphicon glyphicon-lock form-control-feedback"></span>
        </div>
        <div class="form-group has-feedback">
            <select v-model="registe.sex" class="form-control">
                <option value="" disabled selected>请选择性别</option>
                <option value="男">男</option>
                <option value="女">女</option>
            </select>
        </div>
        <div class="form-group has-feedback">
            <input type="text" class="form-control" id="age" readonly="readonly" placeholder="出生年月"
                   v-model='registe.age'/>
        </div>
        <div class="row">
            <!--<div class="col-xs-8">
              <div class="checkbox icheck">
              </div>
            </div>-->
            <!-- /.col -->
            <div class="col-xs-2"></div>
            <div class="col-xs-4">
                <button id="registerSub" type="button" class="btn btn-primary btn-block btn-flat" @click="registerSub">
                    注册
                </button>
            </div>
            <div class="col-xs-4">
                <button type="button" class="btn btn-primary btn-block btn-flat" @click="goback">返回</button>
            </div>
            <!-- /.col -->
        </div>
        <!-- /.social-auth-links -->

    </div>
    <!-- /.login-box-body -->
</div>
<!-- /.login-box -->
<script src="${request.contextPath}/statics/libs/jquery.min.js"></script>
<script src="${request.contextPath}/statics/libs/vue.min.js"></script>
<script src="${request.contextPath}/statics/libs/bootstrap.min.js"></script>
<script src="${request.contextPath}/statics/libs/jquery.slimscroll.min.js"></script>
<script src="${request.contextPath}/statics/libs/fastclick.min.js"></script>
<script src="${request.contextPath}/statics/libs/app.js"></script>
<script src="${request.contextPath}/statics/plugins/layer/layer.js"></script>
<script src="${request.contextPath}/statics/plugins/layui/laydate/laydate.js"></script>
<script type="text/javascript">
    var vm = new Vue({
        el: '#rrapp',
        data: {
            username: '',
            password: '',
            captcha: '',
            error: false,
            errorMsg: '',
            src: 'captcha.jpg',
            showFlag: true,
            registe: {}

        },
        created: function () {
            setTimeout(function () {
                laydate.render({
                    elem: "#age",
                    done: function (value, date, endDate) {
                        vm.registe.age = value;
                    }
                });
            }, 5 * 100);
        },
        beforeCreate: function () {
            if (self != top) {
                top.location.href = self.location.href;
            }
        },
        methods: {
            refreshCode: function () {
                this.src = "captcha.jpg?t=" + $.now();
            },
            login: function (event) {
                var data = "username=" + vm.username + "&password=" + vm.password + "&captcha=" + vm.captcha;
                $.ajax({
                    type: "POST",
                    url: "sys/login",
                    data: data,
                    dataType: "json",
                    success: function (result) {
                        if (result.code == 0) {//登录成功
                            parent.location.href = 'index.html';
                        } else {
                            vm.error = true;
                            vm.errorMsg = result.msg;
                            vm.refreshCode();
                        }
                    }
                });
            },
            register: function () {
                vm.showFlag = false;
                vm.registe.sex = '';
            },
            goback: function () {
                vm.showFlag = true;
            },
            registerSub: function () {
                $('#registerSub').button('loading').delay(1000).queue(function () {
                    var username = vm.registe.username;
                    var password = vm.registe.password;
                    var sex = vm.registe.sex;
                    var age = vm.registe.age;
                    if (username == null || password == null || sex == null || age == null) {
                        layer.alert("必要数据不能为空！");
                        $('#registerSub').button('reset');
                        $('#registerSub').dequeue();
                        return;
                    }
                    $.ajax({
                        type: "POST",
                        url: "sys/user/register",
                        contentType: "application/json",
                        data: JSON.stringify(vm.registe),
                        success: function (r) {
                            if (r.code === 0) {
                                $('#registerSub').button('reset');
                                $('#registerSub').dequeue();
                                layer.msg("注册成功!", {icon: 1});
                                vm.showFlag = true;
                                vm.registe = {};
                            } else {
                                layer.alert("注册失败：" + r.msg);
                                $('#registerSub').button('reset');
                                $('#registerSub').dequeue();
                            }
                        },
                        error: function () {
                            layer.alert("系统异常，请联系管理员！");
                        }
                    });
                });
            }
        }
    });
</script>
</body>
</html>
